package DAO;

import java.util.ArrayList;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.Query;

import model.Cliente;

@Stateless
public class ClienteDAO 
{
@Inject
EntityManager em;

public void insertar(Cliente c)
{
	em.persist(c);
	
}
public Cliente buscar(String id)
{
	return em.find(Cliente.class, id);
}
public ArrayList<Cliente> listar(String val)
{
	val = val.toLowerCase();
	String sql="SELECT * FROM Cliente c WHERE lower(c.cli_nombre) LIKE '"+val+"%' OR c.cli_cedula LIKE '"+val+"%'";
	Query q = em.createNativeQuery(sql, Cliente.class);
	return (ArrayList<Cliente>) q.getResultList();
}
	
public ArrayList<Cliente> listarClientesSinUsr()
{

	String sql="select * from cliente where usr_login is null";
	Query q = em.createNativeQuery(sql, Cliente.class);
	return (ArrayList<Cliente>) q.getResultList();
}
	
public void actualizarCliente(Cliente c)
{
	em.merge(c);
}

}
